package com.water.camera.mark;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.water.camera.bean.EditItem;
import com.water.camera.databinding.LayoutWatermark64Binding;

import java.text.SimpleDateFormat;
import java.util.ArrayList;

public class Mark64 extends BaseMark {

    LayoutWatermark64Binding binding;

    public Mark64(@NonNull Context context) {
        super(context);
    }

    public Mark64(@NonNull Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public Mark64(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    protected void init(int type) {
        if (type == 0) {
            binding = LayoutWatermark64Binding.inflate(LayoutInflater.from(getContext()));
            addView(binding.getRoot());
            int n = binding.linear.getChildCount();
            for (int i = 2; i < n; i++) {
                binding.linear.getChildAt(i).setVisibility(View.GONE);
            }
        } else {
            binding = LayoutWatermark64Binding.inflate(LayoutInflater.from(getContext()), this, true);
        }
        update();
    }

    @Override
    public void update() {
        setText(binding.binding2, "jingwei64", binding.binding1);
        String[] ss = new EditItem("jingwei64").getStringPoints();
        binding.binding2.setText(ss[1]);
        binding.binding4.setText(ss[0]);

        setText(binding.binding6, "imei64", binding.binding5);

        setText(binding.binding8, "time64", binding.binding7);
        setTime(binding.binding8, new SimpleDateFormat("yyyy年MM月dd日"));
        setWeek(binding.binding9);
        setTime(binding.binding10, new SimpleDateFormat("HH:mm"));

        setText(binding.binding12, "didian64", binding.binding11);
        setText(binding.binding14, "phone64", binding.binding13);

        setText(binding.binding16, "weather64", binding.binding15);
        setText(binding.binding18, "height64", binding.binding17);
        setText(binding.binding20, "beizhu64", binding.binding19);

        super.update();
    }

    @Override
    public ArrayList<EditItem> getEditItems() {
        ArrayList<EditItem> list = new ArrayList<>();
        list.add(new EditItem("jingwei64", "经纬度"));
        list.add(new EditItem("imei64", "IMEI"));
        list.add(new EditItem("time64", "时间", true));
        list.add(new EditItem("didian64", "地点"));

        list.add(new EditItem("phone64", "电话"));
        list.add(new EditItem("weather64", "天气"));
        list.add(new EditItem("height64", "海拔"));
        list.add(new EditItem("beizhu64", "备注"));

        return list;
    }

    @Override
    public void onValueChange(EditItem item) {
        if (item.isTime) {
            setTime(binding.binding8, new SimpleDateFormat("yyyy年MM月dd日"));
            setWeek(binding.binding9);
            setTime(binding.binding10, new SimpleDateFormat("HH:mm"));
        } else if (item.isPoint()) {
            String[] ss = new EditItem("jingwei64").getStringPoints();
            binding.binding2.setText(ss[1]);
            binding.binding4.setText(ss[0]);
        } else {
            super.onValueChange(item);
        }
    }

    @Override
    public void onShowChange(EditItem item) {
        if (item.isPoint()) {
            if (item.show) {
                showView(binding.binding1, binding.binding3);
            } else {
                hideView(binding.binding1, binding.binding3);
            }
        } else {
            super.onShowChange(item);
        }
    }
}
